<html>
<head><meta charset="utf-8"><title>detect codegen backend · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html">detect codegen backend</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="148063215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148063215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148063215">(Nov 20 2018 at 19:55)</a>:</h4>
<p>Is there a way to detect the codegen backend being used (e.g. llvm vs cranelift) ?</p>



<a name="148063222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148063222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148063222">(Nov 20 2018 at 19:55)</a>:</h4>
<p>Ideally a cfg() macro ?</p>



<a name="148065094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148065094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148065094">(Nov 20 2018 at 20:22)</a>:</h4>
<p>That <em>seems</em> like a bad thing to check. From the user's perspective there shouldn't be a difference.</p>



<a name="148068528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148068528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148068528">(Nov 20 2018 at 21:12)</a>:</h4>
<p>yeah, but the std library needs to be able to tell, when using backend-specific intrinsics for example</p>



<a name="148068600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148068600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148068600">(Nov 20 2018 at 21:13)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> ^</p>



<a name="148070409"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148070409" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148070409">(Nov 20 2018 at 21:42)</a>:</h4>
<blockquote>
<p>yeah, but the std library needs to be able to tell, when using backend-specific intrinsics for example</p>
</blockquote>
<p>shouldnt instead the intrinsics have the same name and type and just their implementration differ?</p>



<a name="148070450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148070450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148070450">(Nov 20 2018 at 21:43)</a>:</h4>
<p>for rustc intrinsincs yes, but i am skeptical about cranelift's ability to provide all the numerous llvm intrinsics that e.g. correspond to sse instructions</p>



<a name="148070539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148070539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148070539">(Nov 20 2018 at 21:44)</a>:</h4>
<p>wouldn't that be more of a "does platform support feature X" flag though?</p>



<a name="148071261"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148071261" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dan Gohman <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148071261">(Nov 20 2018 at 21:56)</a>:</h4>
<p>One of the ideas with the Cranelift backend is that we can make it automatically fall back to the LLVM backend if it encounters something it doesn't support.</p>



<a name="148071376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148071376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dan Gohman <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148071376">(Nov 20 2018 at 21:58)</a>:</h4>
<p>That would be the quickest path to providing users with a working system without having to implement the entire long tail of LLVM's feature set first.</p>



<a name="148071521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148071521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148071521">(Nov 20 2018 at 22:01)</a>:</h4>
<p>also IMO using LLVM intrinsics from libraries is a complete hack that needs to be replaced at some point</p>



<a name="148071616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148071616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148071616">(Nov 20 2018 at 22:02)</a>:</h4>
<p>too bad platform-intrinsics wasn't used more</p>



<a name="148071752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148071752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dan Gohman <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148071752">(Nov 20 2018 at 22:04)</a>:</h4>
<p>So to answer the original question: no, there isn't a way to detect the backend, and it's too early at this point to even predict if we'll want to add one.</p>



<a name="148379236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148379236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148379236">(Nov 26 2018 at 16:36)</a>:</h4>
<p>thanks <span class="user-mention" data-user-id="130125">@Dan Gohman</span> that makes sense. Do you think that if Cretonne can fall back to LLVM it would make sense for stdsimd to use <code>"platform-intrinsics"</code> instead of <code>link_llvm_intrinsics</code> ? Or it would not matter ?</p>



<a name="148379564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148379564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dan Gohman <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148379564">(Nov 26 2018 at 16:40)</a>:</h4>
<p>I don't know the specifics of the "platform-intrinsics" vs <code>link_llvm_intrinsics</code> mechanisms.</p>



<a name="148379714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148379714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dan Gohman <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148379714">(Nov 26 2018 at 16:42)</a>:</h4>
<p>The basic plan is that Cranelift will implement most of the functionality of the LLVM intrinsics, though they look a little different in Cranelift's IR and builder APIs than in LLVM's.</p>



<a name="148379732"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148379732" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148379732">(Nov 26 2018 at 16:42)</a>:</h4>
<p>IIUC <code>link_llvm_intrinsics</code> allows using <code>extern { fn llvm.foo.bar(...) -&gt; .. }</code> to call llvm intrinsics directly from Rust as if one was calling C.<br>
<code>"platform-intinriscs"</code> allows importing functions that are provided by Rust, e.g., <code>extern "platform-intrinsics" { fn foo_bar(...) -&gt; ... }</code></p>



<a name="148379758"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148379758" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148379758">(Nov 26 2018 at 16:43)</a>:</h4>
<p>the difference is that Rust can change what platform intrinsics do, and provide different implementations for the different backends, while <code>link_llvm_intrinsics</code> cannot do that</p>



<a name="148379782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148379782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dan Gohman <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148379782">(Nov 26 2018 at 16:43)</a>:</h4>
<p>Ah, ok. So yeah, Cranelift won't be providing magical functions named like "llvm.foo.bar".</p>



<a name="148382203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148382203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148382203">(Nov 26 2018 at 17:17)</a>:</h4>
<p><span class="user-mention" data-user-id="130125">@Dan Gohman</span> but could cranelift identify these functions and fall back to LLVM in this case ?</p>



<a name="148382462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148382462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dan Gohman <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148382462">(Nov 26 2018 at 17:21)</a>:</h4>
<p>We could make that work, though in most cases, what we really want to do is implement the feature in Cranelift too :-).</p>



<a name="148382584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148382584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148382584">(Nov 26 2018 at 17:22)</a>:</h4>
<p>for x86, we would only need to implement ~2000 SIMD intrinsics, looks like a lot, but is a process that might be automated, the problem is how do we hook them up in stdsimd</p>



<a name="148382695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148382695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148382695">(Nov 26 2018 at 17:24)</a>:</h4>
<p>the logic to choose which intrinsic to emit has to be somewhere, and currently stdsimd uses <code>link_llvm_intrinsic</code>. @eddyb suggested moving that into rustc so that stdsimd just calls <code>platform-intrinsics</code>, and <code>rustc</code> chooses between llvm or cranelift intrinsics</p>



<a name="148382721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148382721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148382721">(Nov 26 2018 at 17:24)</a>:</h4>
<p>we could do that, but to me this looks like moving the problem from stdsimd into rustc, and i'm not so sure that rustc can solve it better than stdsimd does</p>



<a name="148382834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/detect%20codegen%20backend/near/148382834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dan Gohman <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/detect.20codegen.20backend.html#148382834">(Nov 26 2018 at 17:26)</a>:</h4>
<p>In Cranelift, these things aren't calls to intrinsics. They're just instructions. Rustc seems like it's able to emit those instructions directly, while stdsimd isn't.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>